package com.cloudkinto.controller.order.allocate;


import com.cloudkinto.base.BaseController;
import com.cloudkinto.bo.order.allocate.AllocateCancelQueryBo;
import com.cloudkinto.bo.order.allocate.BackAllocateShelfBo;
import com.cloudkinto.bo.order.outbound.BackOutboundShelfBo;
import com.cloudkinto.bo.order.outbound.OutboundCancelQueryBo;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.order.outbound.OutboundCancelService;
import com.cloudkinto.vo.order.allocate.BackAllocateShelfVo;
import com.cloudkinto.vo.order.outbound.BackOutboundShelfVo;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 调拨截单 前端控制器
 * </p>
 *
 * @author long
 * @since 2024-12-09
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "wms调拨截单")
@RequestMapping("/api/admin/wms/allocateCancel")
public class AllocateCancelWmsController extends BaseController {
    private final OutboundCancelService cancelService;

    @UserSessionRequired
    @GetMapping("/pageInit")
    @ApiOperation(value = "调拨截单查询初始化", notes = "调拨截单查询初始化")
    public SingleResult pageInit() {
        return cancelService.pageInit(getCurrentUserId(), getTenantId());
    }

    @UserSessionRequired
    @PostMapping("/listPage")
    @ApiOperation(value = "调拨截单查询（分页）", notes = "调拨截单查询（分页）")
    public PageResult listPage(@RequestBody @Validated AllocateCancelQueryBo bo) {
        bo.setTenantId(getTenantId());
        return cancelService.getAllocateListPage(bo);
    }

    @UserSessionRequired
    @PostMapping("/listPageStatusSta")
    @ApiOperation(value = "调拨截单状态统计", notes = "调拨截单状态统计")
    public SingleResult listPageStatusSta(@RequestBody @Validated AllocateCancelQueryBo bo) {
        bo.setTenantId(getTenantId());
        return cancelService.allocateListPageStatusSta(bo);
    }

    @UserSessionRequired
    @GetMapping("/getBackAllocateDetail/{id}")
    @ApiModelProperty(value = "获取回库上架详情", notes = "获取回库上架详情")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = BackAllocateShelfVo.class))
    public SingleResult<BackAllocateShelfVo> getBackAllocateDetail(@PathVariable("id") Long id) {
        return SingleResult.success(cancelService.getBackAllocateDetail(id));
    }

    @UserSessionRequired
    @PostMapping("/backAllocateShelf")
    @ApiOperation(value = "回库上架", notes = "回库上架")
    public SingleResult backAllocateShelf(@RequestBody @Validated BackAllocateShelfBo req) {
        return cancelService.backAllocateShelf(req, getCurrentUserId(), getUserName());
    }

    @UserSessionRequired
    @PutMapping("/markFail/{id}")
    @ApiOperation(value = "标记失败", notes = "标记失败(id为截单id)")
    public SingleResult markFail(@PathVariable("id") Long id) {
        return cancelService.allocateMarkFail(id, getCurrentUserId(), getUserName());
    }
}